package com.camera2.http;


import android.util.Log;

import com.camera2.Utils.StreamUtils;
import com.camera2.local.SharedPrefer;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;


public class Register {
    public static String register(String username, String password, String name) throws Exception {

        HttpClient client = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(GlobalUrl.getRegisterUrl());
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("mobile", username);
        jsonParam.put("password", password);
        jsonParam.put("username", name);
        StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");//解决中文乱码问题
        entity.setContentEncoding("UTF-8");
        entity.setContentType("application/json");
        httpPost.setEntity(entity);

        HttpResponse response = client.execute(httpPost);
        InputStream is = response.getEntity().getContent();
        String result = StreamUtils.readStream(is);
        Log.i("register", "register: " + result);
        int code = response.getStatusLine().getStatusCode();
        JSONObject jsonObj = new JSONObject(result);
        String msg = jsonObj.getString("msg");
        return msg;
//        if (code == 200) {
//
//        } else {
//            return null;
//        }
    }
}
